<template>
	<view>
		<view class="head">
			<img src="https://oa.yuxiang123.cn/assets/task/shop/login_bj.png" mode="widthFix" style="width: 100%;">
		</view>
		<view class="budd">
            <view class="budd-tile">
                <view class="budd-phone">
                    <view class="phone">手机号</view>
                    <view class="phone-input">
                        <input class="input" placeholder="请输入手机号" v-model="phone" :focus="true" type="number" placeholder-style="color: #D6D6D6;  " adjust-position="false"/>  
                    </view>
                </view>
				<view class="budd-phone">
                    <view class="phone">密码</view>
                    <view class="phone-input">
                        <input type="password" class="input" placeholder="请输入密码" v-model="password" :focus="true"  placeholder-style="color: #D6D6D6;  " />  
                    </view>
                </view>
                <!-- <view class="budd-phone ">
                    <view class="phone">验证码</view>
                    <view class="phone-input_2">
                        <input class="input" placeholder="请输入验证码" v-model="code"  type="number" placeholder-style="color: #D6D6D6;  "/>  
                        <view class="btn" @click="getCode()">{{getCodeText}}</view>
                    </view>
                    
                </view> -->
            </view>
			<view class="wx_wc"><view class="phone_bt" @click="log()">登录</view></view>
			<view style="display: flex;flex-wrap: wrap;color: #9E9E9E;margin-top: 20rpx;">
				<view style="width: 38%;text-decoration: underline;text-align: left;margin-left: 12%;" @click="toPages('/subone/public/forget_password')">忘记密码</view>
				<view style="width: 38%;text-decoration: underline;text-align: right;margin-right: 12%;" @click="toPages('/subone/public/register')">注册账号</view>
			</view>
			<view class="radio">
				<image src="@/static/radio.png" class="box" v-if="isCheck==false" @click="isCheck = true"></image>
				<image src="@/static/radio_2.png" class="box" v-else  @click="isCheck = false"></image>
				<view class="text">已阅读并同意《<text @click="toPages('agreement')">用户协议</text>》和《<text @click="toPages('privacy')">隐私政策</text>》</view>
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				//动态赋值
				getCodeText: '获取验证码',
				getCodeisWaiting:false,
				phone:'',
				password:'',
				code:'',
				isCheck:false,
			}
		},
		onLoad(p) {
			uni.setStorageSync('num', 1);
			console.log(p)
			if(p.isCheck == 'false' || p.isCheck == '' || !p.isCheck){
				this.isCheck = false;
			}else{
				this.isCheck = true;
			}
		},
		methods: {
			log:function(){
				var that = this;
				// if(that.code == ''){
				// 	return  that.$Toast('验证码不可为空!')
				// }
				if(that.password == ''){
					return  that.$Toast('密码不可为空!')
				}
				if(that.isCheck==false){
					return that.$Toast('请阅读并同意《用户协议》以及《隐私政策》')
				}
				// #ifdef APP-PLUS ||H5

				if(uni.getSystemInfoSync().platform == 'ios'){
					var login_source = 'ios';
				}else{
					var login_source = 'android';
				}

				uni.request({
					url:'https://oa.yuxiang123.cn/api/index/login',
					method:'POST',
					header:{"content-type":"application/x-www-form-urlencoded"},
					data:{'password':this.password,mobile:this.phone,login_source:login_source,is_shop:1,invite_user_id:uni.getStorageSync('invite_user_id')},
					success: (res) => {
						this.$Toast(res.data.msg)
						if(res.data.code == 1){
							uni.setStorageSync('token', res.data.data.token);
							uni.setStorageSync('userInfo', res.data.data.user);
							setTimeout(() => {
								if(res.data.data.is_new == 1){
									uni.navigateTo({
										url:'/subone/public/addUserInfo'
									})
								}else{
									if(uni.getStorageSync('task_user_id')){
										uni.request({
											url: 'https://oa.yuxiang123.cn/api/distribute_task/add_distribute_invite',
											header:{
												"content-type": "application/x-www-form-urlencoded"
											},
											data:{
												token:uni.getStorageSync('token'),
												task_user_id:uni.getStorageSync('task_user_id')
											},
											method: 'POST'
										})
										uni.setStorageSync('task_user_id','');
										// uni.reLaunch({
										// 	url:'/subone/user/distribute_task'
										// })
										uni.showModal({
											title: '申请团长提交成功',
											content: '你已成功提交团长申请!申请通过后，我们将通过邮件或短信通知你感谢你的支持和耐心等待!',
											success: function (res) {
												uni.switchTab({
													url:'/pages/shop/shopClass'
												})
												
											}
										});
									}else{
										uni.navigateBack({
											delta:1
										})
									}
								}
							}, 1000)
						}
					}
				})
				// #endif
				
				// #ifdef MP-WEIXIN
				let invite_user_id=uni.getStorageSync('invite_user_id')?uni.getStorageSync('invite_user_id'):0;
				uni.login({
					success: function (res) {
						if(res.code) {
							uni.request({
								url:'https://oa.yuxiang123.cn/api/index/login',
								method:'POST',
								header:{"content-type":"application/x-www-form-urlencoded"},
								data:{openid_code:res.code,'password':that.password,'invite_user_id':invite_user_id,mobile:that.phone,autocity:uni.getStorageSync('autocity'),is_shop:1},
								success: (res) => {
									uni.showToast({
										title:res.data.msg,
										icon:'none'
									});
									if(res.data.code == 1){
										uni.setStorageSync('token', res.data.data.token);
										uni.setStorageSync('userInfo', res.data.data.user);
										setTimeout(() => {
											if(res.data.data.is_new == 1){
												uni.navigateTo({
													url:'/subone/public/addUserInfo'
												})
											}else{
												uni.switchTab({
													url:'/pages/shop/shopClass'
												})
											}
										}, 1000)
									}
								}
							})						
						}else{
						}
					}					
				});
				// #endif
				
			},
			//跳转
			toPages:function(url){
				uni.navigateTo({
					url:url
				})
			},
			//验证码
			getCode() {
				var that = this;
				uni.hideKeyboard()
				if(this.getCodeisWaiting == true){
					return
				}
				if(this.phone.length < 11){
					return this.$Toast('手机号错误')
				}
				that.getCodeText = "发送中..."
				that.getCodeisWaiting = true;
				this.$show();
				this.$http.post('index/mobile_code',{
					mobile:this.phone
				}).then((res)=>{
					console.log(res);
					this.$hide()
					if(res.data.ret==1){
						that.getCodeText = "发送中..."
						that.getCodeisWaiting = true;
						//示例用定时器模拟请求效果
						setTimeout(() => {
							uni.showToast({
								title: '验证码已发送',
								icon: "none"
							});
							that.setTimer();
						})
					}else{
						that.getCodeText = "发送验证码"
						that.getCodeisWaiting = false;
						uni.showToast({
							title: res.data.msg,
							icon: "none"
						});
						
					}
				})
			},
			setTimer() {
				let holdTime = 60;
				this.getCodeText = "重新获取(60)"
				this.Timer = setInterval(() => {
					if (holdTime <= 0) {
						this.getCodeisWaiting = false;
						this.getCodeText = "获取验证码"
						clearInterval(this.Timer);
						return;
					}
					this.getCodeText = "重新获取(" + holdTime + ")"
					holdTime--;
				}, 1000)
			},
		}
	}
</script>
<style lang="scss">
.btn{
    text-align: right;
    width: 260upx;
}
.budd-tile{
    width: 100%;
	text-align: -webkit-center;
	padding-top: 20upx;
}
.phone-input_2{
    align-items: center;
    display: flex;
    margin-top: 20upx;
    width: 100%;
    height: 108upx;
    flex-shrink: 0;
    border-radius: 8px;
    background: #F6F7F9;
    text-align: left;
    padding-left: 20upx;
    .input{
        height: 108upx;
    }
}
.phone-input{
    .input{
        margin-top: 20upx;
        width: 100%;
        height: 108upx;
        flex-shrink: 0;
        border-radius: 8px;
        background: #F6F7F9;
        text-align: left;
        padding-left: 20upx;
    }
}

.phone{
    text-align: left;
}
.budd-phone{
    text-align: -webkit-right;
    width: 660upx;
    margin-top: 40upx;
}
.budd{
	border-radius: 40upx;
    margin-top: -40upx;
    background: #fff;
}
.radio{
	display: flex;
	align-items: center;
	justify-content: center;
	margin-top: 40upx;
	.box{
		width:40upx;
		height:40upx;
	}
	.text{
		font-size: 26upx;
		color: #999999;
		margin-left: 10upx;
		text{
			color: #3662EC;
			text-decoration:underline;
		}
	}
}
.wx_wc_1{
	width: 100%;
	text-align: -webkit-center;
	padding-top: 120upx;
}
.wx_wc{
	width: 100%;
	text-align: -webkit-center;
	padding-top: 70upx;
}
.wx_bt{
	border-radius: 51px;
	background: #3662EC;
	width: 630upx;
	height: 108upx;
	flex-shrink: 0;
	font-size: 34upx;
    line-height: 108upx;
	color: #fff;
	
}
.phone_bt{
	border-radius: 51px;
	background: #3662EC;
	width: 630upx;
	height: 95upx;
	flex-shrink: 0;
	font-size: 34upx;
    line-height: 95upx;
	color: #fff;
}
.head{
	width: 100%;
	//height:530upx;
	//background: url('https://oa.yuxiang123.cn/assets/task/shop/login_bj.png');
}

.code{
	display: flex;
	align-items: center;
	.input{
		flex: 1;
	}
	.btn{
		font-size: 28upx;
	}
}

.button{
	background-color: $uni-color;
	width: 90%;
	margin: auto;
	margin-top: 60upx;
	text-align: center;
	font-size: 30upx;
	line-height: 80upx;
	border-radius: 50upx;
	font-weight: bold;
}




</style>
